#!/bin/sh

# configure.sh
# xD-OS
#
# Created by James Johns on 09/08/2009.
# Copyright 2009 xD-Dunce. All rights reserved.

debug=0
verbose=0
clean=0
purge=0

while [ "$1" != "" ]; do
    case $1 in
        --debug-mode)           debug=1
                                ;;
        --verbose )				verbose=1
                                ;;
		--clean )				clean=1
								;;
		--purge-logs )			purge=1
								;;
		--full-clean )			clean=1
								purge=1
								;;
        * )                     exit 1
    esac
    shift
done

if test $purge -eq 1
then
	:>configure.log
fi

## CLEAN flags
if test $clean -eq 1
then
	echo "Clean... YES"
	if egrep -l '#define VERBOSE' source/kernel/global.h >> configure.log
	then
		echo "VERBOSE MODE REMOVED"	>> configure.log
		sed '$d' < source/kernel/global.h > source/kernel/temp.h; mv source/kernel/temp.h source/kernel/global.h
		sed '$d' < source/kernel/global.h > source/kernel/temp.h; mv source/kernel/temp.h source/kernel/global.h
		sed '$d' < source/kernel/global.h > source/kernel/temp.h; mv source/kernel/temp.h source/kernel/global.h
	fi
	if egrep -l '#define DEBUG' source/kernel/global.h	>> configure.log
	then
		echo "DEBUG MODE REMOVED"	>> configure.log
		sed '$d' < source/kernel/global.h > source/kernel/temp.h; mv source/kernel/temp.h source/kernel/global.h
		sed '$d' < source/kernel/global.h > source/kernel/temp.h; mv source/kernel/temp.h source/kernel/global.h
		sed '$d' < source/kernel/global.h > source/kernel/temp.h; mv source/kernel/temp.h source/kernel/global.h
	fi
	make clean 2> configure.log
fi

## DEBUG MODE flags
if test $debug -eq 1
then
	if egrep -l '#define DEBUG' source/kernel/global.h >> configure.log
	then
		debug=1
	else
		echo '#ifndef DEBUG'	>> source/kernel/global.h
		echo '#define DEBUG'	>> source/kernel/global.h
		echo '#endif'			>> source/kernel/global.h
	fi
	echo "Debug.. YES"
	echo "DEBUG MODE ENABLED"	>> configure.log
else
	echo "Debug... NO"
fi

## VERBOSE MODE flags
if test $verbose -eq 1
then
	if egrep -l '#define VERBOSE' source/kernel/global.h >> configure.log
	then
		verbose=1
	else
		echo '#ifndef VERBOSE'	>> source/kernel/global.h
		echo '#define VERBOSE'	>> source/kernel/global.h
		echo '#endif'			>> source/kernel/global.h
	fi
	echo "Verbose... YES"
	echo "VERBOSE MODE ENABLED"	>> configure.log
else
	echo "Verbose... NO"
fi

## template
# if test $var -eq 1
# then
#		echo "config var" >> source/kernel/global.h
# fi
## end template

exit 0
